package com.by.auto;

import com.auth0.jwt.JWT;
import com.by.token.TokenTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * date 2025/2/12 14:12
 * author bjj
 * decoration
 * version 1.0
 * since jdk11
 */
// 自动配置
@AutoConfiguration
// 当JWT存在的时候，自动配置
@ConditionalOnClass({JWT.class})
// 当TokenProperties存在的时候，自动配置
@EnableConfigurationProperties(value = {TokenProperties.class})
// 当token.enabled=true的时候，自动配置
@ConditionalOnProperty(prefix = "token", name = "enabled", matchIfMissing = true)
public class TokenAutoConfigure {
    @Bean
    @ConditionalOnMissingBean(value = {TokenTemplate.class})
    public TokenTemplate tokenTemplate(TokenProperties tokenProperties) {
        return new TokenTemplate(tokenProperties);
    }
}
